package com.snail.cloud.controller;

import com.snail.cloud.apis.PayFeignApi;
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import io.github.resilience4j.springboot3.circuitbreaker.monitoring.endpoint.CircuitBreakerEndpoint;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author snail
 * @date 2024/11/6
 */
@RestController
public class OrderCircuitController {

    @Resource
    private PayFeignApi payFeignApi;
    @Autowired
    private CircuitBreakerEndpoint circuitBreakerEndpoint;
    @Autowired
    private PathMappedEndpoints pathMappedEndpoints;

    @GetMapping("/feign/pay/circuit/{id}")
    @CircuitBreaker(name = "cloud-payment-service", fallbackMethod = "myCircuitFallback")
    public String myCircuitBreaker(@PathVariable("id") Integer id) {
        return payFeignApi.myCircuit(id);
    }

    public String myCircuitFallback(Throwable t) {
        return "myCircuitFallback，系统繁忙，请稍后再试—----/（ToT）/~~";
    }
}
